package com.zeta.eduservice.controller.question;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zeta.base.BaseController;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.question.PaperTypeAndChoicequestion;
import com.zeta.eduservice.entity.question.PaperTypeAndQuestion;
import com.zeta.eduservice.service.PaperTypeAndQuestionService;

/**
 * <p>
 * 试卷大题类型 题目中间表 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2021-04-20
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/paper_type_and_question")
public class PaperTypeAndQuestionController extends BaseController<PaperTypeAndQuestion>{
@Autowired
private PaperTypeAndQuestionService  paperTypeAndQuestionService;
	@Override
	public IService<PaperTypeAndQuestion> getBaseService() {
		// TODO Auto-generated method stub
		return paperTypeAndQuestionService;
	}

	@PostMapping("addlist")
	public R addquestionList(@RequestBody String list) {
		JSONObject j1 = JSONObject.parseObject(list);
		 String string = j1.getString("list");
		 String papertypeid = j1.getString("papertypeid");
		 JSONArray parseArray = JSONObject.parseArray(string);
			List<String> nodes = JSONObject.parseArray(parseArray.toJSONString(), String.class);
			for(String i:nodes) {
				PaperTypeAndQuestion entity = new PaperTypeAndQuestion();
				entity.setQuestionId(i);
				entity.setPaperTypeId(papertypeid);
				paperTypeAndQuestionService.save(entity);
		}
		
			return R.ok();

		
	}
}

